Skip to content

Introduce user profiles#132522

Merged
azasypkin merged 37 commits intomainfrom
feature/user-profile
Jun 9, 2022
Merged

Introduce user profiles#132522
azasypkin merged 37 commits intomainfrom
feature/user-profile

Conversation

@azasypkin
Copy link
Copy Markdown
Contributor

@azasypkin azasypkin commented May 19, 2022

Summary

This PR merges feature/user-profile branch into main branch.

Blocked by: #132645


Release note: Users can have their personal avatars now.

@azasypkin azasypkin added release highlight Team:Security Platform Security: Auth, Users, Roles, Spaces, Audit Logging, etc t// release_note:feature Makes this part of the condensed release notes v8.3.0 Feature:Security/User Profile ci:no-auto-commit Disable auto-committing changes on CI labels May 19, 2022
azasypkin and others added 4 commits May 23, 2022 09:24
* Add user profile UI

* add code doc

* More

* Fix nav control for anonymous users

* Move presentational logic outside form row

* Fix disabled state and update profile api

* remove presentational logic from form row

* wip

* Fix initials

* .

* empty user avatar

* simplify reserved user screen

* .

* unit tests

* type fixes

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* .

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* .

* .

* .

* .

* .

* .

* Review#1: handle UI inconsistencies, update avatar in the navigation bar when profile data is updated, etc.

* Fix type errors.

* Use different validation model for the first and subsequent submits.

* Review#2: move change password form to a modal, support users authenticated via authentication proxies.

* Use proper test subject for the password change Cancel button.

* Review#3: retry profile activation requests.

* Review#4: align text color of the non-editable profile fields with the designs.

* Review#4: improve warning message for the change password form when changing password for Kibana system users.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Aleh Zasypkin <aleh.zasypkin@elastic.co>
@thomheymann thomheymann marked this pull request as ready for review May 24, 2022 10:59
@thomheymann thomheymann requested review from a team as code owners May 24, 2022 10:59
@azasypkin azasypkin added ci:deploy-cloud and removed ci:no-auto-commit Disable auto-committing changes on CI labels Jun 3, 2022
@azasypkin
Copy link
Copy Markdown
Contributor Author

Okay, CI is finally green and we have a functioning Cloud deployment 🎉

@jportner jportner self-requested a review June 3, 2022 17:44
Copy link
Copy Markdown
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making those changes, @azasypkin! Leaving you two final comments for the re-review:

Disabled text color

Changed to $euiColorDisabled (I assume you meant this one and not $euiColorDisabledText) in 92988cd

They're actually the same hex values, but I did indeed intend to use $euiColorDisabledText (or euiTheme.colors.disabledText), just in case the EUI team changes the value specifically for the text version in the future. Can we change that?

Page template padding

With the swapping that happened between KibanaPageTemplate and EuiPageTemplate, I think the padding got messed up again in the process. It looks like there is no padding being applied now, apparent when viewing at small viewport sizes.

image

I'm guessing this is happening because there is a paddingSize="none" prop being applied to the EuiPageTemplate. If so, can you remove that prop (which should theoretically apply the default paddingSize="l")?

Otherwise, this looks good to me. I'm going to go ahead and approve it now so I don't hold you up any further, under the assumption that you can address the above comments. Thanks so much!

@azasypkin
Copy link
Copy Markdown
Contributor Author

They're actually the same hex values, but I did indeed intend to use $euiColorDisabledText (or euiTheme.colors.disabledText), just in case the EUI team changes the value specifically for the text version in the future. Can we change that?

Hmm, when I use euiTheme.colors.disabledText I get rgb(162, 171, 186) (#a2abba), but with euiTheme.colors.disabled I get rgb(171, 180, 196) (#abb4c4, the one we have in design mockups). Looking at this code this code I assumed it was intentional, or not @MichaelMarcialis ?

Copy link
Copy Markdown
Contributor

@jportner jportner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if you intended to address #132645 before merging this to main or not, but I just wanted to remind you of it.
If you want to follow up afterwards, that's fine.

I commented with a few minor nits from that issue and a few new ones that I found. Take them or leave them 😄 LGTM

Comment on lines +29 to +40
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
if (context) {
if (image.width >= image.height) {
canvas.width = maxSize;
canvas.height = Math.floor((image.height * maxSize) / image.width);
} else {
canvas.height = maxSize;
canvas.width = Math.floor((image.width * maxSize) / image.height);
}
context.drawImage(image, 0, 0, canvas.width, canvas.height);
const resizedDataUrl = canvas.toDataURL();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit of code (0, 0) always draws the image from the top left corner.
So, if for example you had an image that was much taller than it was wide, uploading it as your avatar would only show the topmost part of the image.

It bugged me a bit so I figured out how to make it use the appropriate offset to center an image:

diff --git a/x-pack/plugins/security/public/account_management/user_profile/utils.ts b/x-pack/plugins/security/public/account_management/user_profile/utils.ts
index fd153502884..3ef60ad585e 100644
--- a/x-pack/plugins/security/public/account_management/user_profile/utils.ts
+++ b/x-pack/plugins/security/public/account_management/user_profile/utils.ts
@@ -28,15 +28,19 @@ export function resizeImage(imageUrl: string, maxSize: number) {
       try {
         const canvas = document.createElement('canvas');
         const context = canvas.getContext('2d');
+        let xOffset = 0;
+        let yOffset = 0;
         if (context) {
           if (image.width >= image.height) {
             canvas.width = maxSize;
             canvas.height = Math.floor((image.height * maxSize) / image.width);
+            xOffset = Math.floor((canvas.height - canvas.width) / 2);
           } else {
             canvas.height = maxSize;
             canvas.width = Math.floor((image.width * maxSize) / image.height);
+            yOffset = Math.floor((canvas.width - canvas.height) / 2);
           }
-          context.drawImage(image, 0, 0, canvas.width, canvas.height);
+          context.drawImage(image, xOffset, yOffset, canvas.width, canvas.height);
           const resizedDataUrl = canvas.toDataURL();
           return resolve(resizedDataUrl);
         }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funnily enough, centering "tall" images works much worse for the image set I have since the head in tall photos is usually close to (0,0) and centering clips the head sometimes like in the picture below:

image

I'll keep as is for now, and we can revisit it with @thomheymann once he's back

Comment on lines +31 to +35
export function useUserProfile<T extends UserData>(dataPath?: string) {
const { userProfiles } = useApiClients();
const dataUpdateState = useObservable(userProfiles.dataUpdates$);
return useAsync(() => userProfiles.get<T>(dataPath), [userProfiles, dataUpdateState]);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder about my prior feedback: #127624 (comment)

This is tracked as part of #132645. Since we are no longer shipping this enhancement with 8.3, I think we should take the time to go ahead and rename this to something else like useMyUserProfile

@azasypkin
Copy link
Copy Markdown
Contributor Author

I'm not sure if you intended to address #132645 before merging this to main or not, but I just wanted to remind you of it.
If you want to follow up afterwards, that's fine.

Thanks for the reminder! Yeah, we agreed to handle most of the feedback recorded in #132645 separately.

@MichaelMarcialis
Copy link
Copy Markdown
Contributor

Hmm, when I use euiTheme.colors.disabledText I get rgb(162, 171, 186) (#a2abba), but with euiTheme.colors.disabled I get rgb(171, 180, 196) (#abb4c4, the one we have in design mockups). Looking at this code this code I assumed it was intentional, or not @MichaelMarcialis ?

Ah, you're right. I was looking at the old Sass variables. Some of the newer Emotion colors are calculated slightly differently than they were previously and we still need to update the design system in Figma to get them back in sync. Thanks for catching this. In any case, let's go ahead and proceed with euiTheme.colors.disabledText here.

@azasypkin
Copy link
Copy Markdown
Contributor Author

In any case, let's go ahead and proceed with euiTheme.colors.disabledText here.

Roger that, switched to disabledText in dda0a10, thanks.

@kibana-ci
Copy link
Copy Markdown

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #25 / apis Monitoring _health endpoint no data returns an empty state when no data

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
security 385 400 +15

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
security 99 100 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
security 472.5KB 444.4KB -28.0KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
cloud 8.4KB 8.2KB -183.0B
security 50.2KB 97.9KB +47.7KB
total +47.5KB
Unknown metric groups

API count

id before after diff
security 179 197 +18

async chunk count

id before after diff
security 20 21 +1

ESLint disabled line counts

id before after diff
security 25 26 +1

References to deprecated APIs

id before after diff
enterpriseSearch 26 30 +4

Total ESLint disabled count

id before after diff
security 27 28 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@azasypkin azasypkin merged commit 9ea8730 into main Jun 9, 2022
@azasypkin azasypkin deleted the feature/user-profile branch June 9, 2022 06:07
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Jun 9, 2022
@tylersmalley tylersmalley added ci:cloud-deploy Create or update a Cloud deployment and removed ci:deploy-cloud labels Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting ci:cloud-deploy Create or update a Cloud deployment Feature:Security/User Profile release_note:feature Makes this part of the condensed release notes Team:Security Platform Security: Auth, Users, Roles, Spaces, Audit Logging, etc t// v8.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.